package com.reider.log4AS3.utils
{
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;
	
	dynamic public class ScopeManagger extends Proxy
	{
		
		private var ownedNames:Array;
		private var controlScope:Object;
		private var targetScope:Object;
			
		public function ScopeManagger(controlScope:Object,targetScope:Object,ownedNames:Array)
		{
			this.ownedNames = ownedNames;
			this.controlScope = controlScope;
			this.targetScope = targetScope;
		}
		
		override flash_proxy function getProperty(name:*):*
		{
			var method:String = String(name)
			if(ownedNames.indexOf(method)!= -1){
				if(controlScope.hasOwnProperty(method)){
					return controlScope[method];
				}
			}else{
				if(targetScope.hasOwnProperty(method)){
					return targetScope[method];
				}
			}
			//trace(name)
		 	return onNoMethod as Function;
        }
        
        public function onNoMethod(... args):void
        {
        	trace("No Correct Method Found")
        }
	}
}